import 'package:flutter/material.dart';
import 'package:flutter_trip/util/string_util.dart';
import 'package:flutter_trip/util/view_util.dart';
import 'package:flutter_trip/widget/login_widget.dart';

import '../widget/input_widget.dart';

class LoginPage extends StatefulWidget {
  const LoginPage({super.key});

  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  bool loginEnable = false;
  String? userName;
  String? password;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [..._background(), _content()],
      ),
    );
  }

  _background() {
    return [
      Positioned.fill(
          child: Image.asset(
        "images/login-bg1.png",
        fit: BoxFit.cover,
      )),
      Positioned.fill(
          child: Container(
        decoration: BoxDecoration(color: Colors.black12),
      ))
    ];
  }

  _content() {
    return Positioned.fill(
      left: 25,
      right: 25,
      child: ListView(
        children: [
          hiSpace(height: 100),
          const Text(
            "账号密码登录",
            style: TextStyle(fontSize: 26, color: Colors.white),
          ),
          hiSpace(height: 40),
          InputWidget(
            "请输入账号",
            onChanged: (text) {
              userName = text;
              _checkInput();
            },
          ),
          hiSpace(height: 10),
          InputWidget(
            "请输入密码",
            obscureText: true,
            onChanged: (text) {
              password = text;
              _checkInput();
            },
          ),
          hiSpace(height: 45),
          LoginButton(
            "登录",
            enable: loginEnable,
            onPressed: () => _login(),
          ),
          hiSpace(height: 10),
          Align(
            alignment: Alignment.centerRight,
            child: InkWell(
              onTap: () => _jumpRegistPage(),
              child: const Text(
                "注册账号",
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
          // hiSpace(height: 40),
          // hrPlaceholder(height: 100, strokeWidth: 5),
          // hiSpace(height: 40),
          // Row(children: [
          //   hrPlaceholder(width: 30,height: 30),
          //   hiSpace(width: 10),
          //   hrPlaceholder(width: 30,height: 30),
          //   hiSpace(width: 10),
          //   hrPlaceholder(width: 30,height: 30),
          //   hiSpace(width: 10),
          //   hrPlaceholder(width: 30,height: 30),
          // ],)
        ],
      ),
    );
  }

  _checkInput() {
    bool enable = false;
    if (isNotEmpty(userName) && isNotEmpty(password)) {
      enable = true;
    }
    setState(() {
      loginEnable = enable;
    });
  }

  _login() {
    print("_login");
  }

  _jumpRegistPage() {
    print("_jumpRegistPage");
  }
}
